import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import importPlugin from '@opentiny/vue-vite-import'
import {serverIp,fileUpload} from "./src/config/index.js";

// https://vitejs.dev/config/
export default defineConfig({
    resolve: {
        extensions: ['.js', '.jsx', '.vue']
    },
    server:{
        proxy: {
            '/api': {
                target: `http://localhost:2443`,
                changeOrigin: true,  // 允许跨域
                rewrite: path => path.replace(/^\/api/,'')
            },
            '/upload': {
                target: fileUpload,
                changeOrigin: true,  // 允许跨域
                rewrite: path => path.replace(/^\/upload/,''),
                // secure: false,
                // Headers: {
                //   'Referer': 'https://smms.app'
                // }
            },
        },
    },
    plugins: [
        vue(),
        importPlugin(
            [
                {
                    libraryName: '@opentiny/vue',
                    split: '-'
                },
                {
                    libraryName: `@opentiny/vue-icon`,
                    libraryDirectory: 'lib',
                    customName: (name) => {
                        return `@opentiny/vue-icon/lib/${name.replace(/^icon-/, '')}.js`
                    }
                }
            ],
            'pc'
        )
    ],
    define: {
        'process.env': {...process.env}
    }
})
